<?php
$v_agency_id = 0;
if(isset($_REQUEST['agency_id'])){
	$v_agency_id = trim($_REQUEST['agency_id']);
}

$v_cate_id = 0;
if(isset($_REQUEST['cate_id'])){
	$v_cate_id = intval(trim($_REQUEST['cate_id']));
}

$v_filter = '';
if(isset($_REQUEST['filter'])){
	$v_filter = $_REQUEST['filter'];
}
echo $v_filter;

if(isset($_REQUEST['method'])){	
	$v_method = $_REQUEST['method'];
}else
	$v_method = 1;
$v_status = 2;


if(isset($_REQUEST['offset'])){
	$v_offset=$_REQUEST['offset'];
}
else
	$v_offset=1;
$v_limit = CONST_LIMIT_AF_PAGE;

if(isset($_REQUEST['page'])){
	$page=$_REQUEST['page'];
}
else
	$page=1;

//echo "status=".$v_status;
//echo "method=".$v_method;
if(_is_sqlserver()){
/*
	$cmd = @mssql_init("Onegate_AFGetAll", $conn);
	@mssql_bind($cmd, "@p_status", $v_status, SQLINT4);
	@mssql_bind($cmd, "@p_method", $v_method, SQLINT4);
	@mssql_bind($cmd, "@p_filter", $v_filter, SQLVARCHAR);
	@mssql_bind($cmd, "@p_agency_id", $v_agency_id, SQLINT4);
	@mssql_bind($cmd, "@p_cate_id", $v_cate_id, SQLINT4);
*/
	$v_table = '';
	$v_column = '';
/*
	$cmd = @mssql_init(" Onegate_AFGetAllByConditions ", $conn);
	@mssql_bind($cmd, "@p_status", $v_status, SQLINT4);
	@mssql_bind($cmd, "@p_method", $v_method, SQLINT4);
	@mssql_bind($cmd, "@p_filter", $v_filter, SQLVARCHAR);
	@mssql_bind($cmd, "@p_agency_id", $v_agency_id, SQLINT4);
	@mssql_bind($cmd, "@p_cate_id", $v_cate_id, SQLINT4);
	@mssql_bind($cmd, "@pTable", $v_table, SQLVARCHAR);
	@mssql_bind($cmd, "@pColumn", $v_column, SQLVARCHAR);
	$result = @mssql_execute($cmd);
	$arr_result = _get_row_to_array($result); 
	@mssql_free_result($result);
*/

	$sql = "Exec Onegate_AFGetAllByConditions " ;
	$sql = $sql.$v_status;
	$sql = $sql.",".$v_method;
	$sql = $sql.",'".$v_filter."'";
	$sql = $sql.",".$v_agency_id;
	$sql = $sql.",".$v_cate_id;
	$sql = $sql.",'".$v_table."'";
	$sql = $sql.",'".$v_column."'";

	$ado_conn->SetFetchMode(ADODB_FETCH_NUM);
	$arr_result = $ado_conn->GetAll($sql); 	
	$v_total_af_count = $arr_result[0][0];


	$pager  = Pager::getPagerData($v_total_af_count, $v_limit, $page);
	$page   = $pager->page;
  	$offset = $pager->offset +1; 
  	$limit = $pager->limit;
	
	$cmd = @mssql_init("Onegate_AFGetByConditions", $conn);
	@mssql_bind($cmd, "@p_status", $v_status, SQLINT4);
	@mssql_bind($cmd, "@p_method", $v_method, SQLINT4);
	@mssql_bind($cmd, "@p_filter", $v_filter, SQLVARCHAR);
	@mssql_bind($cmd, "@p_agency_id", $v_agency_id, SQLINT4);
	@mssql_bind($cmd, "@p_cate_id", $v_cate_id, SQLINT4);
	@mssql_bind($cmd,"@offset", $offset,SQLINT4);	
	@mssql_bind($cmd,"@limit",$limit,SQLINT4);	

	$result = mssql_execute($cmd); 
	$arr_all_report = _get_row_to_array($result);
	@mssql_next_result($result);
	$arr_all_af = _get_row_to_array($result); 
	@mssql_free_result($result);
	
	$v_number_of_af = sizeof($arr_all_af);
}
?>